home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / comm / irc / epic4-mos.lha / share / epic / script / commandqueues < prev    next >
Text File  |  2002-09-18  |  4KB  |  116 lines

  1. # All these aliases take commands as arguments and have the property that
  2. # they will not exand those commands prior to execution, making them safe.
  3. #
  4. # This may require some explanation:
  5. #
  6. # The ircii language has the concept of "expansion", whereby variable
  7. # references are replaced with the variable values and escaped characters
  8. # are unescaped.  This is one of the side effects of an eval.  In the
  9. # following two commands, if entered from the command line, the first will
  10. # whois the nick "\\`anderer", and the second will whois "\`anderer",
  11. # because the eval will unescape it.
  12. #
  13. #  /whois \\`anderer
  14. #  /eval whois \\`anderer
  15. #
  16. # This is from the command line.  If these commands are executed from an
  17. # alias, the first command will whois "\`anderer", and the second will
  18. # whois "`anderer".  This is because commands within an alias are always
  19. # expanded prior to execution.  There is no way to stop this, but you can
  20. # control it by passing a variable to the whois command instead of the raw
  21. # text.  Since expansion only occurs once, the variables expansion will
  22. # "shelter" the text from being expanded.
  23. #
  24. # If you wish to add more levels of expansion, you use more evals.  If you
  25. # wish to have _no_ expansion, you keep all your text in variables, and
  26. # avoid using eval.
  27. #
  28. # It is easy to see that there may be occasions where you may want to whois
  29. # someone from within a hook without having to worry about expansion.  This
  30. # is easy enough.  /whois does not expand its arguments, however, hooks can
  31. # generate floods, so you put the whois in a timer say.  The problem with
  32. # this is that /timer _does_ expand its arguments, so you end up with an
  33. # extra level of expansion to deal with.
  34. #
  35. # These aliases solve these problems.  Commands are given as arguments and
  36. # are normally not expanded, just as if they had been given to a built in
  37. # command.  If you wish to have them expanded when they are run, precede
  38. # them with /eval, or use a /timer or a /queue instead.
  39.  
  40. package qcmd
  41.  
  42. #
  43. # Usage:
  44. #  scmd [server [command]]
  45. #
  46. # Execute command on server _without_ expanding command.
  47. #
  48. alias scmd xeval -s $0 {$1-}
  49.  
  50. #
  51. # Usage:
  52. #  1cmd [time [command]]
  53. #
  54. # command will not be executed if the same command has been executed in
  55. # the last time seconds.
  56. #
  57. alias 1cmd {
  58.     @ :foo = encode($tolower($1-))
  59.     @ :eserv = encode($tolower($servername()))
  60.     if (time() - 1cmd[$eserv][$foo] >= [$0]) {
  61.         @ 1cmd[$eserv][$foo] = time()
  62.         $1-
  63.     }
  64.     if ((!rand(10)) && time() != 1cmd[$eserv]) {
  65.         @ 1cmd[$eserv] = time()
  66.         foreach 1cmd[$eserv] bar {
  67.             if (1cmd[$eserv][$bar] < time()) {
  68.                 @ 1cmd[$eserv][$bar] = []
  69.             }
  70.         }
  71.     }
  72. }
  73.  
  74. #
  75. # Usage:
  76. #  qcmd [queue [command]]
  77. #  fqcmd [queue [command]]
  78. #
  79. # Queue command, and schedule a timer for later execution.  Prevents flooding.
  80. # fqcmd adds the command to the beginning of the queue instead of the end.
  81. #
  82. #  q1cmd [time [queue [command]]]
  83. #  fq1cmd [time [queue [command]]]
  84. #
  85. # The same as "1cmd {time} qcmd {queue} {command}", only, the command also
  86. # won't be scheduled if the same command is already scheduled.
  87. #
  88. fe (q push fq unshift) cmd op {
  89.     alias ${cmd}1cmd unless (match("$2-" $qcmd[$servernum()][$1]))\{1cmd \$0 ${cmd}cmd \$1-\}
  90.     alias ${cmd}cmd {
  91.         if (servernum() < 0) {
  92.             $1-
  93.             return
  94.         } elsif (1 < #) {
  95.             @ :bar = [$1-]
  96.             @ ${op}(qcmd.${servernum()}.$0 \"$msar(gr/\\/\\\\/\"/\\\"/bar)\")
  97.         } elsif (isconnected()) {
  98.             @ :foo = []
  99.             if (1 == #) {
  100.                 @ foo = [$0]
  101.             } elsif (0 == #) {
  102.                 foreach qcmd[$servernum()] bar {
  103.                     @ foo = bar
  104.                     break
  105.                 }
  106.             }
  107.             if (@foo) {
  108.                 @ :bar = shift(qcmd[$servernum()][$foo])
  109.                 $msar(gr/\\\\/\\/\\\"/\"/bar)
  110.             }
  111.         }
  112.         if (@bar) ^timer -ref qcmd.$servernum() 5 qcmd
  113.     }
  114.     @ aliasctl(alias set ${cmd}cmd $sar(g/\${op}/${op}/$aliasctl(alias get ${cmd}cmd)))
  115. }
  116.